;; defines error conditions used in the parser

(in-package :oali.core)

(define-condition parser-error (error)
  (
   ;; entity that is a subject of error - e.g. actual argument, mispelled symbol, undefined variable etc.
   (entity :initarg :entity :initform nil :reader entity)

   ;; location where an error occurs in the source form
   (where :initarg :where :initform nil :reader where)))


;; facility, that is not implemented shall come in the entity slot
(define-condition not-implemented (parser-error)
  ())

;; internal error cause shall come in the entity slot
(define-condition internal-error (parser-error)
  ())



(define-condition function-parsing-error (parser-error)
  ())

(define-condition unknown-expression (function-parsing-error)
  ((expression :initarg :expression :reader expression)))

;; symbol that is defined multiple times shall come in the `entity' slot
(define-condition multiple-definition (function-parsing-error)
  (
   ;; location of the previous definition
   (previous-definition :initarg :previous-definition :reader previous-definition)))

;; symbol, that is not defined before being used shall come in the `entity' sloty
(define-condition not-defined (function-parsing-error)
  ())

(define-condition invalid-arguments-count (function-parsing-error)
  (
   ;; actual arguments' count
   (actual :initarg :actual :reader actual)

   ;; expected argument's count
   (expected :initarg :expected :reader expected)
   ))

;; actual argument shall come in the entity slot
(define-condition illegal-argument (function-parsing-error)
  (
   ;; expected argument
   (expected :initarg :expected :reader expected)

   ;; position in the argument list, starting from 0
   (pos :initarg :pos :reader pos)
   ))

